﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/table.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/dwz/themes/default/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href="${pageContext.request.contextPath}/dwz/themes/css/core.css" rel="stylesheet" type="text/css" media="screen" />
<link rel="stylesheet" href="${pageContext.request.contextPath}/ztree/css/zTreeStyle/zTreeStyle.css" />
<link type="text/css" href="${pageContext.request.contextPath}/jquery/ui/css/ui-lightness/jquery-ui-1.8.18.custom.css" rel="stylesheet" />
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/ui/js/jquery-ui-1.8.18.custom.min.js"></script>
<script src="${pageContext.request.contextPath}/ztree/js/jquery.ztree.all.min.js" type="text/javascript"></script>
<script type="text/javascript">
	//集成jquery ztree插件
	var setting = {
		async:{
			enable: true,
			url: "role?method=getAssignPermission&id=${role.id}",
		},
		check: {
			enable: true
		},
		data: {
			simpleData: {
				enable: true,
				pIdKey: "pid",
			}
		}
	};
	
	$(function() {
		//集成jquery多tab页
		$('#tabs').tabs();
		$.fn.zTree.init($("#checkbox_tree"), setting);
	});

	function save() {
		let zTreeObj = $.fn.zTree.getZTreeObj("checkbox_tree");
		let checkedNodes = zTreeObj.getCheckedNodes(true);

		let array = new Array();
		for (let i=0;i<checkedNodes.length;i++){
			array.push(checkedNodes[i].id);
		}
		console.log(array)
		$.post("role?method=updatePermissionRole",{"array":array,"id":'${role.id}'},function (result) {
			if (result.code=="200"){
				alert("修改成功");
			}else {
				alert(result.message);
			}
		},"json")
	}
</script>
<table border="0" cellpadding="0" cellspacing="0" class="table_border">
	<tr>
		<td>
			<table width="100%" border="0" cellpadding="0" cellspacing="0"
                class="table_right">
                <tr>
                    <td>
                        <font style="font-size: 12px"><strong>为角色分配许可</strong></font>
                    </td>
                    <td width="25" height="26" align="right">
                    </td>
                </tr>
            </table>
		</td>
	</tr>
	<tr height="50">
		<td>
			<div id="tabs">
				<ul>
					<li><a href="#tabs-1">角色信息</a></li>
					<li><a href="#tabs-2">许可信息</a></li>
				</ul>
				<div id="tabs-1" style="background: #FFFFFF">
					代码：${role.code} <br /> <br />
					名称：${role.name} <br /> <br />
					描述：${role.remark}
				</div>
				<div id="tabs-2" style="background: #FFFFFF">
					<table>
						<tr>
							<td></td>
						</tr>
						<tr>
							<td>
								<ul id="checkbox_tree" class="ztree">
								</ul>
							</td>
						</tr>
					</table>
				</div>
			</div>
		</td>
	</tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0"
	class="table_padding">
	<tr>
		<td height="21" align="right">
			<table align="left">
				<tr>
					<td width="50px">
						<a class="button" href="javascript:void(0)"  onclick="save()">
							<span>保存</span>
						</a>
					</td>
					<td width="50px">
						<a class="button" href="javascript:void(0)" onclick="window.history.back()">
							<span>返回</span>
						</a>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

